package p270jp.pxv.android.activity;

import android.content.ComponentCallbacks;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import androidx.databinding.DataBindingUtil;
import androidx.databinding.ViewDataBinding;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Objects;
import p014ae.AbstractActivityC0152s0;
import p045be.ImagePagerAdapter;
import p047bg.C1124a;
import p064c6.Preconditions;
import p116e.ActionBar;
import p134ei.AnalyticsScreenName;
import p134ei.PixivAnalytics;
import p165fo.Subscribe;
import p189gn.AbstractC3435a;
import p216hn.Lambda;
import p216hn.Reflection;
import p270jp.pxv.android.R;
import p270jp.pxv.android.activity.BaseActivity;
import p270jp.pxv.android.activity.FullScreenImageActivity;
import p270jp.pxv.android.event.TapFullImageEvent;
import p270jp.pxv.android.legacy.model.GoogleNg;
import p270jp.pxv.android.legacy.model.PixivIllust;
import p270jp.pxv.android.legacy.model.PixivMetaPage;
import p270jp.pxv.android.service.ImageDownloadService;
import p314lg.ActivityFullScreenImageBinding;
import p325m0.MutabilityOwnership;
import p579vo.Qualifier;
import p603wm.AbstractC6949c;
import p677zi.PixivImageLoader;

/* compiled from: FullScreenImageActivity.kt */
/* renamed from: jp.pxv.android.activity.FullScreenImageActivity */
/* loaded from: classes2.dex */
public final class FullScreenImageActivity extends AbstractActivityC0152s0 {

    /* renamed from: P */
    public static final /* synthetic */ int f18353P;

    /* renamed from: M */
    public ActivityFullScreenImageBinding f18354M;

    /* renamed from: N */
    public PixivIllust f18355N;

    /* renamed from: O */
    public final AbstractC6949c f18356O = Preconditions.m9802P(1, new C4005a(this, null, null));

    /* compiled from: ComponentCallbackExt.kt */
    /* renamed from: jp.pxv.android.activity.FullScreenImageActivity$a */
    /* loaded from: classes2.dex */
    public static final class C4005a extends Lambda implements AbstractC3435a<PixivImageLoader> {

        /* renamed from: a */
        public final /* synthetic */ ComponentCallbacks f18357a;

        /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
        public C4005a(ComponentCallbacks componentCallbacks, Qualifier aVar, AbstractC3435a aVar2) {
            super(0);
            this.f18357a = componentCallbacks;
        }

        /* JADX WARN: Type inference failed for: r0v4, types: [java.lang.Object, zi.a] */
        @Override // p189gn.AbstractC3435a
        public final PixivImageLoader invoke() {
            return C1124a.m10173s(this.f18357a).f24118a.m920a().m621a(Reflection.m5499a(PixivImageLoader.class), null, null);
        }
    }

    @Override // p270jp.pxv.android.activity.BaseActivity, androidx.fragment.app.FragmentActivity, androidx.activity.ComponentActivity, p248j2.ActivityC3902g, android.app.Activity
    public void onCreate(Bundle bundle) {
        super.onCreate(bundle);
        ViewDataBinding d = DataBindingUtil.m11369d(this, R.layout.activity_full_screen_image);
        MutabilityOwnership.m3746l(d, "setContentView(this, R.l…tivity_full_screen_image)");
        ActivityFullScreenImageBinding hVar = (ActivityFullScreenImageBinding) d;
        this.f18354M = hVar;
        C1124a.m10196R(this, hVar.f21640r, "");
        ActionBar P0 = m7044P0();
        MutabilityOwnership.m3747j(P0);
        P0.mo6941f();
        PixivAnalytics eVar = this.f18757A;
        MutabilityOwnership.m3746l(eVar, "pixivAnalytics");
        eVar.m6524f(AnalyticsScreenName.VIEWER_ORIGINAL_SIZE, null);
        Bundle extras = getIntent().getExtras();
        MutabilityOwnership.m3747j(extras);
        Serializable serializable = extras.getSerializable("KEY_ILLUST");
        Objects.requireNonNull(serializable, "null cannot be cast to non-null type jp.pxv.android.legacy.model.PixivIllust");
        this.f18355N = (PixivIllust) serializable;
        int i = extras.getInt("KEY_POSITION", 0);
        ArrayList arrayList = new ArrayList();
        PixivIllust pixivIllust = this.f18355N;
        if (pixivIllust != null) {
            if (pixivIllust.pageCount == 1) {
                if (pixivIllust != null) {
                    String originalImageUrl = pixivIllust.metaSinglePage.getOriginalImageUrl();
                    if (originalImageUrl != null) {
                        arrayList.add(originalImageUrl);
                    } else {
                        throw new IllegalArgumentException("Required value was null.".toString());
                    }
                } else {
                    MutabilityOwnership.m3737u("illust");
                    throw null;
                }
            } else if (pixivIllust != null) {
                for (PixivMetaPage pixivMetaPage : pixivIllust.metaPages) {
                    String original = pixivMetaPage.getImageUrls().getOriginal();
                    if (original != null) {
                        arrayList.add(original);
                    } else {
                        throw new IllegalArgumentException("Required value was null.".toString());
                    }
                }
            } else {
                MutabilityOwnership.m3737u("illust");
                throw null;
            }
            ImagePagerAdapter d0Var = new ImagePagerAdapter(arrayList, (PixivImageLoader) this.f18356O.getValue());
            ActivityFullScreenImageBinding hVar2 = this.f18354M;
            if (hVar2 != null) {
                hVar2.f21639q.setAdapter(d0Var);
                ActivityFullScreenImageBinding hVar3 = this.f18354M;
                if (hVar3 != null) {
                    hVar3.f21639q.setCurrentItem(i);
                    PixivIllust pixivIllust2 = this.f18355N;
                    if (pixivIllust2 != null) {
                        GoogleNg resolveGoogleNg = pixivIllust2.resolveGoogleNg();
                        MutabilityOwnership.m3746l(resolveGoogleNg, "illust.resolveGoogleNg()");
                        m12145X0(resolveGoogleNg);
                        return;
                    }
                    MutabilityOwnership.m3737u("illust");
                    throw null;
                }
                MutabilityOwnership.m3737u("binding");
                throw null;
            }
            MutabilityOwnership.m3737u("binding");
            throw null;
        }
        MutabilityOwnership.m3737u("illust");
        throw null;
    }

    @Override // androidx.activity.ComponentActivity, android.app.Activity
    public boolean onCreateOptionsMenu(Menu menu) {
        MutabilityOwnership.m3745m(menu, "menu");
        getMenuInflater().inflate(R.menu.menu_full_image, menu);
        return true;
    }

    @Subscribe
    public final void onEvent(TapFullImageEvent tapFullImageEvent) {
        MutabilityOwnership.m3745m(tapFullImageEvent, "event");
        ActionBar P0 = m7044P0();
        MutabilityOwnership.m3747j(P0);
        if (P0.mo6940h()) {
            ActionBar P02 = m7044P0();
            MutabilityOwnership.m3747j(P02);
            P02.mo6941f();
            return;
        }
        ActionBar P03 = m7044P0();
        MutabilityOwnership.m3747j(P03);
        P03.mo6927x();
    }

    @Override // androidx.activity.ComponentActivity, android.app.Activity
    public boolean onOptionsItemSelected(MenuItem menuItem) {
        MutabilityOwnership.m3745m(menuItem, "item");
        int itemId = menuItem.getItemId();
        if (itemId == 16908332) {
            finish();
            return true;
        } else if (itemId != R.id.menu_save_image) {
            return super.onOptionsItemSelected(menuItem);
        } else {
            ActivityFullScreenImageBinding hVar = this.f18354M;
            if (hVar != null) {
                m4679S0("android.permission.WRITE_EXTERNAL_STORAGE", new BaseActivity.AbstractC4150e(hVar.f21639q.getCurrentItem()) { // from class: ae.b0

                    /* renamed from: b */
                    public final /* synthetic */ int f279b;

                    {
                        this.f279b = r2;
                    }

                    @Override // p270jp.pxv.android.activity.BaseActivity.AbstractC4150e
                    /* renamed from: b */
                    public final void mo408b() {
                        FullScreenImageActivity fullScreenImageActivity = FullScreenImageActivity.this;
                        int i = this.f279b;
                        int i2 = FullScreenImageActivity.f18353P;
                        MutabilityOwnership.m3745m(fullScreenImageActivity, "this$0");
                        PixivIllust pixivIllust = fullScreenImageActivity.f18355N;
                        if (pixivIllust != null) {
                            ImageDownloadService.m4560g(fullScreenImageActivity, pixivIllust, i, ImageDownloadService.EnumC4311a.ORIGINAL);
                        } else {
                            MutabilityOwnership.m3737u("illust");
                            throw null;
                        }
                    }
                });
                return true;
            }
            MutabilityOwnership.m3737u("binding");
            throw null;
        }
    }
}
